package com.punch.common.enums.user.role;

import java.util.Objects;

/**
 * @author tanchangguo
 * @date 2020/7/21 15:53
 * 角色枚举
 */

public enum UserRoleEnum {
    ADMIN(1, "超级管理员"),
    MANAGER(2, "运营人员"),
    ORGAN(3, "机构"),
    SCHOOL(4, "学校"),
    EDUCATION(5, "教育局"),
    FINANCIAL(6, "财务");

    UserRoleEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    private int code;
    private String name;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public static String getName(Integer code) {
        if (code == null) {
            return "";
        }
        for (UserRoleEnum roleEnum : UserRoleEnum.values()) {
            if (roleEnum.getCode() == code) {
                return roleEnum.getName();
            }
        }
        return "";
    }

    public static boolean isAdmin(Integer code) {
        return Objects.equals(code, ADMIN.getCode());
    }

    public static boolean isManager(Integer code) {
        return Objects.equals(code, ADMIN.getCode()) || Objects.equals(code, MANAGER.getCode());
    }


}

